﻿using UnityEngine;
using System.Collections;

public class yourFlame : MonoBehaviour
{
	public GameObject Player;
	public float speedFlame;
	public float disipateVel;
	public bool invertate;
	Color colorObj;
	Color originalColor;
	// Use this for initialization
	void Start ()
	{
		Player = GameObject.FindGameObjectWithTag("Player");
		if(Player.transform.localScale.x < 0)
		{
			invertate = true;
		}
		originalColor = transform.renderer.material.color;
		colorObj = originalColor;
	}
	
	// Update is called once per frame
	void Update () 
	{
		transform.renderer.material.color = colorObj;
		colorObj.a -= disipateVel*Time.deltaTime;
		if(invertate)
		{
			transform.Translate(-speedFlame * Time.deltaTime, 0, 0);
			transform.localScale = new Vector3(-0.5f, 0.5f, 1);

		}else
		{
			transform.Translate(speedFlame * Time.deltaTime, 0, 0);
			transform.localScale = new Vector3(0.5f, 0.5f, 1);
		
		}
		if(colorObj.a < 0)
		{
			Destroy(gameObject);
		}

	}
}
